from clint.textui import colored, puts, formatters


def type_highlight(children, item_width=40):
    """ 根据文件类型， 高亮输出 """
    if children is None or len(children) == 0:
        print("Empty")
        return
    new_line = False
    for child in children:
        file_type = child.get('type')
        if file_type == 'dict':
            color_function = colored.green
        elif file_type is None or file_type == '':
            color_function = colored.red
        else:
            color_function = colored.yellow
        puts(color_function(formatters.min_width(child['name'] + ' ', item_width)), newline=new_line)
        new_line = not new_line
    print()


def log_highlight(level, line):
    level_color = {
        "I": colored.cyan,
        "V": colored.black,
        "D": colored.green,
        "W": colored.yellow,
        "E": colored.red
    }
    puts(level_color[level](line), newline=False)